
using System;
using System.Linq;
using Csla;
using Csla.Data;
using Csla.Security;
using Csla.Validation;
using HousingInfo.DataLinQ;

namespace HousingInfo.Library
{ 
	public partial class AreaDetailBO : Csla.BusinessBase<AreaDetailBO>
	{

		#region Authorization Rules
		protected override void AddAuthorizationRules()
		{
			//TODO: Define authorization rules in AreaDetailBO
			//AuthorizationRules.AllowRead(AreaDetailIDProperty, "AreaDetailBOReadGroup");
			//AuthorizationRules.AllowRead(AreaIDProperty, "AreaDetailBOReadGroup");
			//AuthorizationRules.AllowRead(AreaDetailNameProperty, "AreaDetailBOReadGroup");
			//AuthorizationRules.AllowRead(IsActiveProperty, "AreaDetailBOReadGroup");

			//AuthorizationRules.AllowWrite(AreaIDProperty, "AreaDetailBOWriteGroup");
			//AuthorizationRules.AllowWrite(AreaDetailNameProperty, "AreaDetailBOWriteGroup");
			//AuthorizationRules.AllowWrite(IsActiveProperty, "AreaDetailBOWriteGroup");
		}
		#endregion //Authorization Rules

		private void AssignParentKey(HousingInfo.DataLinQ.AreaDetail data, AreaBO parent)
		{
            data.AreaID = parent.AreaID;
		}

        #region Ham lay ten duong theo id
        public static AreaDetailBO GetName_ByID(int areadetailid)
        {
            return DataPortal.Fetch<AreaDetailBO>(new FilterCriteria_Name_ByID(areadetailid));
        }
        #region khai bao tham so
        private class FilterCriteria_Name_ByID
        {
            public int idareadetails;
            public FilterCriteria_Name_ByID(int id)
            {
                this.idareadetails = id;
            }
        }
        #endregion//end khai bao tham so
        #region Data Access - Fetch
        private void DataPortal_Fetch(FilterCriteria_Name_ByID param)
        {
            using (var mgr = ContextManager<HousingInfo.DataLinQ.HousingInfoDataContext>
                        .GetManager(Database.HousingInfoConnection))
            {
                var data = mgr.DataContext.AreaDetails
                        .Single(r => r.AreaDetailID == param.idareadetails);

                LoadProperty<int>(AreaDetailIDProperty, data.AreaDetailID);
                LoadProperty<int?>(AreaIDProperty, data.AreaID);
                LoadProperty<string>(AreaDetailNameProperty, data.AreaDetailName);
                LoadProperty<bool>(IsActiveProperty, data.IsActive);

                ValidationRules.CheckRules();
            }//using
        }
        #endregion
        #endregion
    }
}
